package com.shangxian.giveithome.controller;

import com.shangxian.giveithome.result.Result;
import com.shangxian.giveithome.entity.ComplaintDO;
import com.shangxian.giveithome.entity.UserDetails;
import com.shangxian.giveithome.annoaction.CheckLoginStatus;
import com.shangxian.giveithome.service.ComplaintService;
import com.shangxian.giveithome.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/complaint")
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private RedisUtils redisUtils;



    @PostMapping(value = "/saveComplaint", name = "更新用户信息")
    @CheckLoginStatus
    public Result saveComplaint(@RequestBody ComplaintDO complaintDO) {
        UserDetails userDetails = redisUtils.getHeader(request);
        complaintDO.setUsId(userDetails.getId());
        return Result.success(complaintService.saveComplaint(complaintDO));
    }

}
